//WIP
//attack(enemy,inventory slot,slot id, element)



with oslot{
if index = argument1+1{
other.slot = id
frametrans = 1
}
}

if irandom(100)>global.evade{
evade = false
}else{
evade = true
}


//adding dmg
currentdmg = 0
currentheal = 0
for (i=0;i<array_height_2d(slot.dmg);i++){
currentdmg += slot.dmg[i,1]*elementVs(slot.dmg[i,2],global.enemybattle.element)
}
currentdmg+=global.dmg
//heal first
if currentheal >0{
with instance_create(38,130,odmgnumber){d=other.currentheal;color = c_green}
if currentheal+global.hp>=global.hpmax{
global.hp = global.hpmax
}else{
global.hp+=currentheal
}
}

//do dmg
if (argument0.ehp - currentdmg)<=0{
//exit battle
//for enemy
with instance_create(194,130,odmgnumber){d=other.currentdmg}
//for player
if !evade{
with instance_create(64,130,odmgnumber){d=argument0.dmg}
}
//for dice
with instance_create(84+32*other.dice/*this should work but doesnt*/,200,odicenumber){r=argument1}
//delete buttons
deletebuttons()
with argument0 {instance_destroy()}

//blood stain? death animation?




exit

}else{
//argument0.ehp -= currentdmg
//with global.enemybattle{
//ehp -= other.currentdmg
//}
argument0.ehp -= currentdmg

}
if (global.hp - argument0.dmg)<=0{
//game over
instance_create(oplayer.x,oplayer.y,opulse)
ocursorslot.battle = false
global.gameover = true
oplayer.visible = false
deletebuttons()
}else{
global.hp -= argument0.dmg

}


///*
//slashes
with instance_create(0,0,oslash){x=64;if other.evade{sprite_index = sslashb}}
instance_create(0,0,oslash)
//*/


//for enemy
with instance_create(194,130,odmgnumber){d=other.currentdmg}
//for player
if evade{
with instance_create(64,130,odmgnumber){d="EVADED"}
}else{
with instance_create(64,130,odmgnumber){d=argument0.dmg}
}

//for dice
with instance_create(84,200,odicenumber){r=argument1}


//create run button
if (global.hp - argument0.dmg)<=0{
with instance_create(0,0,orunbutton){
x=view_xview[0]+60+64
y=view_yview[0]+194
}
}


